package org.example.contestb.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

@Configuration
@EnableWebSocket
public class WebSocketConfig {
    
    /**
     * 注册ServerEndpointExporter，这个bean会自动注册使用了@ServerEndpoint注解的bean
     */
    @Bean
    public ServerEndpointExporter serverEndpointExporter() {
        ServerEndpointExporter exporter = new ServerEndpointExporter();
        return exporter;
    }
    
    /**
     * 注册WebSocketServer为Spring管理的单例
     */
    @Bean
    public WebSocketServer webSocketServer() {
        return new WebSocketServer();
    }
}
